package cmd

import (
	config "code.alibaba-inc.com/agit/quarantine-helper/config"
	"github.com/spf13/cobra"
)

var pipelineCmd = &cobra.Command{
	Use:   "pipeline",
	Short: "execute all sub-command one by one like a pipeline",
	Long:  `execute all sub-command one by one like a pipeline`,
	RunE: func(cmd *cobra.Command, args []string) error {
		var (
			ids []string
			err error
		)
		config.SetDisableStdout()
		ids, err = scan()
		if err != nil {
			return err
		}
		ids, err = filter(ids)
		if err != nil {
			return err
		}
		return displayCommits(ids)
	},
}

func init() {
	rootCmd.AddCommand(pipelineCmd)
	pipelineCmd.Flags().StringVarP(&config.BranchTip, "branchTip", "b", "", "Only print commits that are ancestors of this commit.")
	pipelineCmd.Flags().IntVarP(&config.Limit, "limit", "l", 100, "The maximum commits count.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.ID, "commitID", "i", false, "diplay commit id.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.Message, "message", "m", false, "diplay commit message.")
	//committer
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.CommittedTime, "committedTime", "", false, "diplay commit time.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.CommitterName, "committerName", "", false, "diplay committer name.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.CommitterEmail, "committerEmail", "", false, "diplay committer email.")
	//author
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.AuthoredTime, "authoredTime", "", false, "diplay authored time.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.AuthorName, "authorName", "", false, "diplay author name.")
	pipelineCmd.Flags().BoolVarP(&config.CommitInfo.AuthorEmail, "authorEmail", "", false, "diplay author email.")

	pipelineCmd.Flags().StringVarP(&config.Delimiter, "delimiter", "d", "-088084-", "delimiter to separate output.")

	// whether to show merge commit
	pipelineCmd.Flags().BoolVarP(&config.NoMerges, "no-merges", "", false, "do not show merge commit")
	pipelineCmd.Flags().BoolVarP(&config.QuickScan, "quickScan", "", false, "read commit ids from $GIT_QUARANTINE_PATH/info/commits.")
	pipelineCmd.Flags().BoolVarP(&config.NoQuickScan, "no-quickscan", "", false, "read commit ids from objdir")
}
